package parser

import (
	"ZeroToAll-Go/crawler/engine"
	"regexp"
)

const cityRegx = `<a href="(http://localhost:8080/mock/album.zhenai.com/u/[0-9]+)">([^>]+)</a>`

func ParseCity(contents []byte) engine.ParseResult {
	compile := regexp.MustCompile(cityRegx)
	matches := compile.FindAllSubmatch(contents, -1)
	result := engine.ParseResult{}

	for _, match := range matches {
		name := string(match[2])
		result.Items = append(result.Items, name)
		result.Requests = append(result.Requests, engine.Request{
			Url: string(match[1]),
			ParserFunc: func(bytes []byte) engine.ParseResult {
				return ParseProfile(bytes, name)
			},
		})
	}

	return result
}
